<?php
/**
 * Created by PhpStorm.
 * User: 86158
 * Date: 2020/8/1
 * Time: 15:33
 */

namespace app\merchant\controller\shop;


use app\merchant\controller\AuthController;
use app\merchant\model\order\StoreOrder;
use app\merchant\model\order\StoreOrderCartInfo;
use app\merchant\model\order\StoreOrderStatus;
use app\merchant\model\store\StoreCategory;
use app\merchant\model\store\StoreDescription;
use app\merchant\model\store\StoreProduct;
use app\merchant\model\store\StoreProductAttr;
use app\merchant\model\store\StoreProductAttrResult;
use app\merchant\model\store\StoreProductCate;
use app\merchant\model\system\Express;
use app\merchant\model\system\ShippingTemplates;
use app\merchant\model\system\SystemAttachment;
use app\merchant\model\ump\StorePink;
use \app\merchant\model\user\User;
use app\models\shop\MerchantAdmin;
use app\models\store\StoreServiceList;
use app\models\store\StoreServiceLog;
use app\models\user\UserToken;
use app\Request;
use crmeb\repositories\UserRepository;
use crmeb\services\CacheService;
use crmeb\services\ExpressService;
use crmeb\services\UtilService;
use think\facade\Db;
use crmeb\services\upload\Upload;

class Statistics
{
    private $user;
    public function __construct(Request $request)
    {
        $token = $request->header('Authori-zation');
//        $authInfo   = UserRepository::parseToken($token);
        $user = AuthController::check($token);
        $this->user = $user;
    }

    /**
     * 首页数据
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request)
    {
        $time   = $request->param('time','today');
        $status = $request->param('status',1);
        $page   = $request->param('page',1);
        $limit  = $request->param('limit',10);
        $mer_id = $this->user->id;

        $data['member_all'] = User::where('mer_id',$mer_id)->count();
        $data['member_increase'] = User::whereTime('add_time', $time)->where('mer_id',$mer_id)->count();
        $data['member_agent']    = User::whereTime('add_time', $time)->where('mer_id',$mer_id)->where('is_promoter',1)->count();
        $data['member_proxy']    = User::whereTime('add_time', $time)->where('mer_id',$mer_id)->where('proxy_level','>',0)->count();

        //成交量
        $data['total_money'] = StoreOrder::whereTime('pay_time', $time)->where('paid',1)->where('mer_id',$mer_id)->sum('pay_price');
        //付款订单
        $data['paid_order'] = StoreOrder::whereTime('pay_time', $time)->where('paid',1)->where('mer_id',$mer_id)->count();
        //付款商品数量
        $data['paid_product'] = StoreOrder::whereTime('pay_time', $time)->where('paid',1)->where('mer_id',$mer_id)->sum('total_num');
        //付款会员数
        $data['paid_user'] = StoreOrder::whereTime('pay_time', $time)->where('paid',1)->where('mer_id',$mer_id)->count('DISTINCT uid');

        //待发货
        $data['wait_deliver'] = StoreOrder::where('paid',1)
            ->where('status',0)
            ->where('mer_id',$mer_id)
            ->where( 'shipping_type', 1)
            ->where( 'refund_status', 0)
            ->where( 'is_del', 0)
            ->count();
        // 待付款
        $data['no_pay'] = StoreOrder::where('paid',0)
            ->where('status',0)
            ->where('mer_id',$mer_id)
            ->where( 'refund_status', 0)
            ->where( 'is_del', 0)
            ->count();
        //已完成
        $data['refund'] = StoreOrder::where('paid',1)
            ->where('status',3)
            ->where('mer_id',$mer_id)
            ->where( 'refund_status', 0)
            ->where( 'is_del', 0)
            ->count();
        $where = [
            'page'  => $page,
            'limit' => $limit,
            'order' => '',
            'mer_id'=>$mer_id,
        ];
        // 订单状态
        switch ($status) {
            case 4 :   // 交易完成
                $where['status'] = 4;
                break;
            case 0 :    // 待付款
                $where['status'] = 0;
                break;
            case 1 :    // 待发货
                $where['status'] =1;
                break;
            default :   //待发货
                $where['status'] = 1;
        }

        //列表
        $data['list'] = StoreOrder::OrderList($where);
        return app('json')->successful($data);
    }

    /**
     * 获取备注
     * @return mixed
     */
    public function get_remark()
    {
        $data = UtilService::postMore(['id']);
        if (!$data['id'])  return app('json')->fail('参数错误!');
        $back = StoreOrder::where('id',$data['id'])->field('id,remark')->find()->toArray();
        return app('json')->successful('OK',$back);
    }

    /**
     * 修改备注
     * @return mixed
     */
    public function update_remark()
    {
        $data = UtilService::postMore(['id', 'remark']);
        if (!$data['id'])  return app('json')->fail('参数错误!');
        if ($data['remark'] == '')  return app('json')->fail('请输入要备注的内容!');
        $id = $data['id'];
        unset($data['id']);
        StoreOrder::edit($data, $id);
        return app('json')->successful('备注成功!');
    }

    /**
     * 快递公司列表
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function company()
    {
        $mer_id = $this->user->id;
        $list = Express::where('is_show',1)->where('mer_id',$mer_id)->select()->toArray();
        return app('json')->successful($list);

    }

    /**
     * 发货
     */
    public function update_delivery()
    {
        $data = UtilService::postMore([
            ['id', 0],
            ['type', 1],
            ['delivery_name', ''],
            ['delivery_id', ''],
            ['sh_delivery_name', ''],
            ['sh_delivery_id', ''],
        ]);
        $id = $data['id'];
        if (!$data['id'])  return app('json')->fail('参数错误!');
        switch ((int)$data['type']) {
            case 1:
                //发货
                $data['delivery_type'] = 'express';
                if (!$data['delivery_name']) return app('json')->fail('请选择快递公司');
                if (!$data['delivery_id']) return app('json')->fail('请输入快递单号');
                $data['status'] = 1;
                StoreOrder::edit($data, $id);
                event('StoreProductOrderDeliveryGoodsAfter', [$data, $id]);
                StoreOrderStatus::setStatus($id, 'delivery_goods', '已发货 快递公司：' . $data['delivery_name'] . ' 快递单号：' . $data['delivery_id']);
                break;
            case 2:
                //送货
                $data['delivery_type'] = 'send';
                $data['delivery_name'] = $data['sh_delivery_name'];
                $data['delivery_id'] = $data['sh_delivery_id'];
                unset($data['sh_delivery_name'], $data['sh_delivery_id']);
                if (!$data['delivery_name']) return app('json')->fail('请输入送货人姓名');
                if (!(int)$data['delivery_id']) return app('json')->fail('请输入送货人电话号码');
                else if (!preg_match("/^1[3456789]{1}\d{9}$/", $data['delivery_id'])) return app('json')->fail('请输入正确的送货人电话号码');
                $data['status'] = 1;
                StoreOrder::edit($data, $id);
                event('StoreProductOrderDeliveryAfter', [$data, $id]);
                StoreOrderStatus::setStatus($id, 'delivery', '已配送 发货人：' . $data['delivery_name'] . ' 发货人电话：' . $data['delivery_id']);
                break;
            case 3:
                //虚拟发货
                $data['delivery_type'] = 'fictitious';
                $data['status'] = 1;
                StoreOrder::edit($data, $id);
                event('StoreProductOrderDeliveryAfter', [$data, $id]);
                StoreOrderStatus::setStatus($id, 'delivery_fictitious', '已虚拟发货');
                break;
            default:
                return app('json')->fail('暂时不支持其他发货类型');
                break;
        }
        return app('json')->successful('发货成功!');
    }

    /**
     * 商品详情
     */
    public function order_info()
    {
        $where = UtilService::getMore([
            ['status', ''],
            ['real_name',''],
            ['is_del', 0],
            ['data', ''],
            ['type', ''],
            ['pay_type', ''],
            ['order', ''],
            ['page', 1],
            ['limit', 20],
            ['excel', 0],
            ['id', 0]
        ]);
        $oid = $where['id'];
        if (!$oid || !($order = StoreOrder::get($oid)))
            return app('json')->fail('订单不存在!');
        $orderInfo = StoreOrder::OrderList($where);
        $back = (compact('orderInfo'));

        return app('json')->successful($back);
    }

    /**
     * 获取快递信息
     * @param string $oid
     * @return mixed
     */
    public function express_info()
    {
        $data = UtilService::postMore([
            ['id', 0],
        ]);
        $oid = $data['id'];
        if (!$oid || !($order = StoreOrder::get($oid)))
            return app('json')->fail('订单不存在!');
        if ($order['delivery_type'] != 'express' || !$order['delivery_id']) return app('json')->fail('该订单不存在快递单号!');
        $cacheName = $order['order_id'] . $order['delivery_id'];

        $result = CacheService::get($cacheName, null);
        if ($result === null) {
            $result = ExpressService::query($order['delivery_id']);
            if (is_array($result) &&
                isset($result['result']) &&
                isset($result['result']['deliverystatus']) &&
                $result['result']['deliverystatus'] >= 3)
                $cacheTime = 0;
            else
                $cacheTime = 1800;
            CacheService::set($cacheName, $result, $cacheTime);
        }
        $back = (compact('order','result'));
        return app('json')->successful($back);

    }

    /**
     * 商品列表
     */
    public function product_list()
    {
        $mer_id = $this->user->id;
        $where = UtilService::getMore([
            ['page', 1],
            ['limit', 20],
            ['store_name', ''],
            ['excel', 0],
            ['order', ''],
            ['cate_id', ''],
            ['type', 1]
        ]);
        $where['mer_id'] = $mer_id;
        $back = StoreProduct::ProductList($where);
        return app('json')->successful($back);
    }

    /**
     * 商品列表
     */
    public function goods_status()
    {
        $data = UtilService::getMore([
            ['id', ''],
            ['is_show', ''],
        ]);

        StoreProduct::update(['is_show'=>$data['is_show']],['id'=>$data['id']]);
        return app('json')->successful("操作成功");
    }

    /**
     * 获取订单列表
     * return json
     */
    public function order_list()
    {
        $mer_id = $this->user->id;
        $where = UtilService::getMore([
            ['status', 0],
            ['real_name', ""],
            ['is_del', 0],
            ['data', ''],
            ['type', ''],
            ['pay_type', ''],
            ['order', ''],
            ['page', 1],
            ['limit', 20],
            ['excel', 0]
        ]);
        $where['mer_id'] = $mer_id;
        $back = StoreOrder::OrderList($where);
        return app('json')->successful($back);
    }

    /**
     * 我的--用户信息
     */
    public function userInfo(Request $request)
    {
        $user = MerchantAdmin::where('id', $this->user->id)->find()->toArray();
        $version_name    = Db::table('dl_version')->where('id',$user['version'])->value('name');
        $user['version'] = $version_name;
        if($user){
            return app('json')->success($user);
        }else{
            return app('json')->fail('获取信息失败');
        }
    }

    /**
     * 修改密码
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function changePwd()
    {
        $list = UtilService::postMore([
            ['pwd', ''],
            ['password', '']
        ]);
        $user = MerchantAdmin::where('id', $this->user->id)->find();
        if(!$user){
            return app('json')->fail('账号不存在');
        }
        if(md5($list['pwd']) != $user['pwd']){
            return app('json')->fail('原始密码错误');
        }
        if (strlen(trim($list['password'])) < 6 || strlen(trim($list['password'])) > 16)
            return app('json')->fail('密码必须是在6到16位之间');
        $res = MerchantAdmin::where('id', $this->user->id)->update(['pwd'=>md5($list['password'])]);
        if($res){
            return app('json')->success("修改成功");
        }else{
            return app('json')->fail('修改密码失败');
        }
    }

    /**
     * 退出登录
     * @param Request $request
     */
    public function logout(Request $request)
    {
        $token = $request->header('Authori-zation');
        $tokenData = UserToken::where('token', $token)->find();
        $tokenData->delete();
        return app('json')->success('成功');
    }


    /**
     * 获取产品详细信息
     * @param int $id
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function get_product_info()
    {

        $post = UtilService::postMore([
            ['id', ''],
        ]);
        $id     = $post['id'];
        $mer_id = $this->user->id;
        $list   = StoreCategory::getApiCategory($mer_id)  ;
        $data['tempList'] = ShippingTemplates::where('mer_id',$mer_id)->order('sort', 'desc')->field(['id', 'name'])->select()->toArray();
        $data['cateList'] = $list;
        $data['productInfo'] =  (object)array() ;
        if ($id) {
            $productInfo = StoreProduct::get(['id'=>$id]);
            if (!$productInfo) {
                return app('json')->fail('产品不存在');
            }
            $productInfo['cate_id'] = explode(',', $productInfo['cate_id']);
            $productInfo['description'] = htmlspecialchars_decode(StoreDescription::getDescription($id));
            $productInfo['slider_image'] = is_string($productInfo['slider_image']) ? json_decode($productInfo['slider_image'], true) : [];
            if ($productInfo['spec_type'] == 1) {
                $result = StoreProductAttrResult::getResult($id);
                foreach ($result['value'] as $k => $v) {
                    $num = 1;
                    foreach ($v['detail'] as $dv) {
                        $result['value'][$k]['value' . $num] = $dv;
                        $num++;
                    }
                }
                $productInfo['items'] = $result['attr'];
                $productInfo['attrs'] = $result['value'];
                $productInfo['attr'] = ['pic' => '', 'price' => 0, 'cost' => 0, 'ot_price' => 0, 'stock' => 0, 'bar_code' => '',
                    'weight' => 0, 'volume' => 0, 'brokerage' => 0, 'brokerage_two' => 0,'proxy_one'=>0,'proxy_two'=>0,'proxy_three'=>0];
            } else {
                $result = StoreProductAttrResult::getResult($id);
                $single = isset($result['value'][0]) ? $result['value'][0] : [];
                $productInfo['items'] = [];
                $productInfo['attrs'] = [];
                $productInfo['attr'] = [
                    'pic' => $single['pic'] ?? '',
                    'price' => $single['price'] ?? 0,
                    'cost' => $single['cost'] ?? 0,
                    'ot_price' => $single['ot_price'] ?? 0,
                    'stock' => $single['stock'] ?? 0,
                    'bar_code' => $single['bar_code'] ?? '',
                    'weight' => $single['weight'] ?? 0,
                    'volume' => $single['volume'] ?? 0,
                    'brokerage' => $single['brokerage'] ?? 0,
                    'brokerage_two' => $single['brokerage_two'] ?? 0,
                    'proxy_one'=>$single['proxy_one'] ?? 0,
                    'proxy_two'=>$single['proxy_two'] ?? 0,
                    'proxy_three'=>$single['proxy_three'] ?? 0
                ];
            }
            if ($productInfo['activity']) {
                $activity = explode(',', $productInfo['activity']);
                foreach ($activity as $k => $v) {
                    if ($v == 1) {
                        $activity[$k] = '秒杀';
                    } elseif ($v == 2) {
                        $activity[$k] = '砍价';
                    } elseif ($v == 3) {
                        $activity[$k] = '拼团';
                    }
                }
                $productInfo['activity'] = $activity;
            } else {
                $productInfo['activity'] = ['秒杀', '砍价', '拼团'];
            }
            $data['productInfo'] = $productInfo;
        }
        return app('json')->success('ok',$data);
    }


    /**
     * 保存新建的资源
     */
    public function product_save()
    {
        $mer_id = $this->user->id;
        //免费版本最多发两个商品
        $adminInfo= MerchantAdmin::get(['id'=>$mer_id]);
        $version  = $adminInfo['version'];
        $data = UtilService::postMore([
            ['id', ''],
            ['cate_id', ""],  //1 json字符串
            'store_name',
            'store_info',
            'keyword',
            ['unit_name', '件'],
            ['image', ""],
            ['slider_image', ""], //2 json字符串
            ['postage', 0],
            ['is_sub', 0],
            ['is_pro', 0],
            ['sort', 0],
            ['sales', 0],
            ['ficti', 100],
            ['give_integral', 0],
            ['is_show', 0],
            ['temp_id', 0],
            ['is_hot', 0],
            ['is_benefit', 0],
            ['is_best', 0],
            ['is_new', 0],
            ['mer_use', 0],
            ['is_postage', 0],
            ['is_good', 0],
            ['brokerage', 0],
            ['brokerage_two', 0],
            ['proxy_one', 0],
            ['proxy_two', 0],
            ['proxy_three', 0],
            ['description', ''],
            ['spec_type', 0],
            ['video_link', ''],
            ['items', []],
            ['attrs', ""],//3 json字符串
            ['activity', []]
        ]);
        $id = $data['id'];
        foreach ($data['activity'] as $k => $v) {
            if ($v == '秒杀') {
                $data['activity'][$k] = 1;
            } elseif ($v == '砍价') {
                $data['activity'][$k] = 2;
            } else {
                $data['activity'][$k] = 3;
            }
        }
        $data['activity'] = implode(',', $data['activity']);
        $detail = json_decode($data['attrs'],true);
        $data['price'] = min(array_column($detail, 'price'));
        $data['ot_price'] = min(array_column($detail, 'ot_price'));
        $data['cost'] = min(array_column($detail, 'cost'));
        $attr = $data['items'];
        unset($data['items'], $data['video'], $data['attrs']);
        $cate_arr = json_decode($data['cate_id'],true);
        if (count($cate_arr) < 1)   return app('json')->fail('请选择产品分类');
        $cate_id = $cate_arr;
        $data['cate_id'] = implode(',',$cate_arr);
        if (!$data['store_name'])   return app('json')->fail('请输入产品名称');
        if (!$data['image'])   return app('json')->fail('请上传产品图片');
        $slider_image_arr = json_decode($data['slider_image'],true);
        if (count($slider_image_arr) < 1)   return app('json')->fail('请上传产品轮播图');
        $data['stock'] = array_sum(array_column($detail, 'stock'));
        StoreProduct::beginTrans();
        if ($id) {
            unset($data['sales']);
            StoreProduct::edit($data, $id);
            $description = $data['description'];
            unset($data['description']);
            StoreDescription::saveDescription($description, $id);
            StoreProductCate::where('product_id', $id)->delete();
            $cateData = [];
            foreach ($cate_id as $cid) {
                $cateData[] = ['product_id' => $id, 'cate_id' => $cid, 'add_time' => time()];
            }
            StoreProductCate::insertAll($cateData);
            if ($data['spec_type'] == 0) {
                $attr = [
                    [
                        'value' => '规格',
                        'detailValue' => '',
                        'attrHidden' => '',
                        'detail' => ['默认']
                    ]
                ];
                $detail[0]['value1'] = '规格';
                $detail[0]['detail'] = ['规格' => '默认'];
            }

            $attr_res = StoreProductAttr::createProductAttr($attr, $detail, $id);
            if ($attr_res) {
                StoreProduct::commitTrans();
                return app('json')->success('修改成功!');
            } else {
                StoreProduct::rollbackTrans();
                return app('json')->fail(StoreProductAttr::getErrorInfo());
            }
        } else {
            if($version==1){
                $number = Db::name('store_product')->where('mer_id',$mer_id)->count();
                if($number>=5){
                    return app('json')->fail('免费版本最多发五个商品');
                }
            }
            $data['add_time'] = time();
            $data['code_path'] = '';
            $data['mer_id']    = $mer_id;
            $res = StoreProduct::create($data);
            $description = $data['description'];
            StoreDescription::saveDescription($description, $res['id']);
            $cateData = [];
            foreach ($cate_id as $cid) {
                $cateData[] = ['product_id' => $res['id'], 'cate_id' => $cid, 'add_time' => time()];
            }
            StoreProductCate::insertAll($cateData);
            if ($data['spec_type'] == 0) {
                $attr = [
                    [
                        'value' => '规格',
                        'detailValue' => '',
                        'attrHidden' => '',
                        'detail' => ['默认']
                    ]
                ];
                $detail[0]['value1'] = '规格';
                $detail[0]['detail'] = ['规格' => '默认'];
            }
            $attr_res = StoreProductAttr::createProductAttr($attr, $detail, $res['id']);
            if ($attr_res) {
                StoreProduct::commitTrans();
                return app('json')->success('添加产品成功!');
            } else {
                StoreProduct::rollbackTrans();
                return app('json')->fail(StoreProductAttr::getErrorInfo());
            }
        }
    }


    /**
     * 图片管理上传图片
     * @return \think\response\Json
     */
    public function upload()
    {
        $mer_id = $this->user->id;
        $pid         = \request()->param('pid', 0);
        $upload_type = \request()->get('upload_type', sys_config('upload_type', 1));
        try {
            $path = make_path('attach', 2, true);
            $upload = new Upload((int)$upload_type, [
                'accessKey' => sys_config('accessKey'),
                'secretKey' => sys_config('secretKey'),
                'uploadUrl' => sys_config('uploadUrl'),
                'storageName' => sys_config('storage_name'),
                'storageRegion' => sys_config('storage_region'),
            ]);
            $res = $upload->to($path)->validate()->move("file",$mer_id);
            if ($res === false) {
                return app('json')->fail('上传失败：' . $upload->getError());
            } else {
                $fileInfo = $upload->getUploadInfo();
                if ($fileInfo) {
                    $aliyun_domain          = "http://img.sichuanapp.com/";
                    $fileInfo['dir']        = $aliyun_domain.$fileInfo['name'];
                    $fileInfo['thumb_path'] = $aliyun_domain.$fileInfo['name'];
                    SystemAttachment::attachmentAdd($fileInfo['name'], $fileInfo['size'], $fileInfo['type'], $fileInfo['dir'], $fileInfo['thumb_path'], $pid, $upload_type, $fileInfo['time'],1,$mer_id);
                }
                return app('json')->successful('上传成功', ['src' => $fileInfo['dir']]);
            }
        } catch (\Exception $e) {
            return app('json')->fail('上传失败：' . $e->getMessage());
        }
    }

    /**
     * 获取商品数量
     */
    public function get_goods_number(){
        $mer_id = $this->user->id;
        $onsale     = StoreProduct::where('is_del', 0)->where('is_show', 1)->where('mer_id',$mer_id)->count();
        //待上架产品
        $forsale    = StoreProduct::where('is_del', 0)->where('is_show', 0)->where('mer_id',$mer_id)->count();
        //已经售馨产品
        $outofstock = StoreProduct::getModelObject(['type' => 4])->where('mer_id',$mer_id)->count();
        //警戒库存
        $policeforce = StoreProduct::getModelObject(['type' => 5])->where('mer_id',$mer_id)->count();
        //回收站
        $recycle = StoreProduct::where('is_del', 1)->where('mer_id',$mer_id)->count();
        $data = compact('onsale', 'forsale', 'outofstock', 'policeforce', 'recycle');
        return app('json')->success('ok',$data);
    }

    /**
     * 聊天记录
     * @param Request $request
     * @return mixed
     */
    public function getChat(Request $request)
    {
        $list = UtilService::postMore([
            ['uid', ''],        //对话人id
            ['id', 0],          //指定id查询
            ['direction', 1],   //指定id前后查询  1 向后查询  2向前查询
            ['page', 1],
            ['limit', 10]
        ], $request);
        if(!$list['uid']){
            return app('json')->fail('参数错误');
        }
        $mer_id = 'admin_'.$this->user->id;
        $where = [];
        if($list['id'] > 0){
            //向前查询
            if($list['direction'] == 2){
                $where[] = ['id','<=',$list['id']];
            }else{
                //向后查询
                $where[] = ['id','>=',$list['id']];
            }
        }
        $data = StoreServiceLog::merchant_lst($mer_id,$list['uid'],$list['page'],$list['limit'],$where);
        $data = count($data) ? $data->toArray() : [];
        if (!empty($data)){//存在消息  清空未读信息
            $map['uid'] = $mer_id;
            $map['to_uid'] = $list['uid'];
            $map['type'] = 0;

            $or['uid'] = $list['uid'];
            $or['to_uid'] = $mer_id;
            $or['type'] = 0;

            StoreServiceLog::where(function ($query)use ($map,$or){
                $query->where($map);
            })->whereOr(function ($query)use ($or){
                $query->where($or);
            })->update(['type'=>1]);
        }
        return app('json')->successful($data);
    }

    /**
     * 联系人列表
     * @param Request $request
     * @return mixed
     */
    public function chatList(Request $request)
    {
        $uid = 'admin_'.$this->user->id;
        $page = $request->param('page',1);
        $limit = $request->param('limit',10);
        $data = StoreServiceList::list($uid,$page,$limit);
        return app('json')->successful($data);
    }

    /**
     * 联系人列表
     * @param Request $request
     * @return mixed
     */
    public function delChat(Request $request)
    {
        $id = $request->param('id','');
        if(!$id){
            return app('json')->fail('删除失败');
        }
        $uid = 'admin_'.$this->user->id;
        $res = StoreServiceList::del($id,$uid);
        if(!$res){
            return app('json')->fail('删除失败');
        }
        return app('json')->successful();
    }

}